<!doctype html>
<html>
  <head>
    <title>Test Page for jquery.interval</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.timeout.js"></script>
  </head>
  <body>
    <div id="main">
      <div id="div1">
        <input id="clear1" type="button" value="Clear Timeout #1">
        <span id="text1">This will change in five seconds, unless you click the button to the left.</span>
      </div>
      <div id="div2">
        <input id="clear2" type="button" value="Clear Timeout #2">
        <span id="text2">This will change in ten seconds, unless you click the button to the left.</span>
      </div>
      <div id="div3">This will change after all timeouts have expired, or the first one is cleared.</div>
    </div>

    <script type="text/javascript">
      var t1 = $.timeout(5000);
      var t2 = $.timeout(10000);

      $('#clear1').click(function() { t1.clear() });
      $('#clear2').click(function() { t2.clear() });

      $.when(t1).then(
          function() { $('#text1').text('Timeout #1 expired') },
          function() { $('#text1').text('Timeout #1 cleared') }
      );
      $.when(t2).then(
          function() { $('#text2').text('Timeout #2 expired') },
          function() { $('#text2').text('Timeout #2 cleared') }
      );

      $.when(t1, t2).then(
          function() { $('#div3').text('All timeouts expired') },
          function() { $('#div3').text('First timeout cleared') }
      );
    </script>

  </body>
</html>
